<?php defined("MAIN_DIR") or die("No direct access");

$banks_query = "select * from `bank` where `city_id` = '$_SESSION[city]'";
$letter = UV::readMQ($route->GET('letter'));
if ($letter != "") {
	$banks_query .= " and `name` like '$letter%'";
}
$banks_query .= " order by `name`";

$limit = 20;
$banks_result = mysql_query($banks_query);
$count = mysql_num_rows($banks_result);
$page = 1;
if (isset($_GET['page']))
	$page = $_GET['page'];
$max_page = ceil($count/$limit);
if ($max_page == 0)
	$max_page++;
if ($page > $max_page)
	$page = $max_page;
elseif ($page < 1)
	$page = 1;
$start_list = (ceil($page)-1)*$limit;
$banks_query .= " limit $start_list,$limit";
$banks_result = mysql_query($banks_query);
$banks_count = mysql_num_rows($banks_result);

$head_title = "Список банков в ".$current_city['city_name_pred'];
$head_description = "Адреса и телефоны банков ".$current_city['city_name_rod'];
$head_keywords = "список банков ".mb_strtolower($current_city['city_name'],'utf-8');

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1>Банки <?php echo $current_city['city_name_rod']; ?></h1>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td align="left" valign="top" class="banki_main_col">
			<div class="banki_search_block">
				<div class="banki_poisk">Поиск</div>
				<div class="banki_po_pervoi_bukve">по первой букве в названии банка</div>
				<div id="banki_alfavit"><?php
					$letters = array();
					$letter_res = mysql_query("select * from `bank` where `city_id` = '$_SESSION[city]'");
					while ($letter_row = mysql_fetch_array($letter_res))
					{
						$letter = $letter_row['name'][0].$letter_row['name'][1];
						if (!in_array($letter,$letters))
							$letters[] = $letter;
					}
					for ($i = 144; $i < 176; $i++)
					{
						if ($i == 170 || $i == 172 || $i == 153)
							continue;
						$letter = chr(208).chr($i);
						if (in_array($letter,$letters))
						{
							echo "<a href='?letter=".$letter."'";
							if (isset($_GET['letter']) && $_GET['letter'] == $letter)
								echo " style='font-weight:bold'";
							echo ">".$letter."</a> ";
						}
						else
							echo $letter." ";
					}
					if (isset($_GET['letter']) && $_GET['letter'] != "")
						echo "<a href='/$c_name/banks' style='letter-spacing:0px;'><sup>x</sup></a>";
				?></div>
			</div>
			<div id="banki_table"><?php
				if ($count > 0)
				{
					$i = 0;
					?><table width="100%" border="0" cellspacing="0" cellpadding="0"><?php
					while ($banks_row = mysql_fetch_array($banks_result))
					{
						$i++;
						?><tr valign="middle" >
							<td width="34" align="center" class="banki_table_item banki_table_number"><?php
								echo $i+($page-1)*$limit;
							?></td>
							<td align="left" class="banki_table_item">
								<a href="<?php echo "/$c_name/banks/{$banks_row['link']}.html"; ?>"><?php echo $banks_row['full_name'];?></a>
							</td>
							<td width="398" align="left" class="banki_table_item">
								<?php echo $banks_row['address'].", тел. ".$banks_row['phone'];?>
							</td>
						</tr><?php
					}
					?></table><?php
				}
				else
					echo "<h3 class='gag'>Банки не найдены</h3>";
			?></div>
			<div id="oprosy_table">
				<?php require_once APP."pageskin.php"; ?>
			</div>
		</td>
		<td width="159" align="left" valign="top"><?php
			require_once APP."rating_column.php";
			require_once APP."vacancy_column.php";
		?></td>
	</tr>
</table>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '9' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>